

import java.util.LinkedList;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */




public class Test {
    public static void main(String[] args) {

    }

    public int[] twoSum(int[] nums, int target) {
        for(int i=0;i<nums.length;i++){
            for (int j = 0; j < nums.length; j++) {
                if (j == i) {
                    continue;
                }
                if (nums[i] + nums[j] == target) {
                    int[] arr = {i,j};
                    return arr;
                }
            }
        }
        return null;
    }

    public int timeRequiredToBuy(int[] tickets, int k) {
        int count = 0;
        int i = 0;
        while (true) {
            i = i % tickets.length;
            if(tickets[i] != 0) {
                tickets[i]--;
                count++;
            }
            if (tickets[k] == 0) {
                break;
            }
        }
        return count;
    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode p1 = l1;
        ListNode p2 = l2;
        int sz1 = 0;
        int sz2 = 0;
        while(p1!=null){
            sz1++;
            p1 = p1.next;
        }
        while(p2!=null){
            sz2++;
            p2 = p2.next;
        }
        if(sz2>sz1){
            p1 = l2;
            p2 = l1;
        }else{
            p1 = l1;
            p2 = l2;
        }
        ListNode ret = p1;
        while(p1!=null && p2!=null){
            int val = p1.val+p2.val;
            if(val>9){
                if(p1.next==null){
                    p1.next = new ListNode(1);
                }else{
                    p1.next.val+=1;
                }
                val %= 10;
                p1.val = val;

            }else{
                p1.val = val;
            }
            p1 = p1.next;
            p2 = p2.next;
        }
        // if(p1==null && p2!=null){
        //     ListNode p3 = l1;
        //     while(p3.next == p2){
        //         p3 = p3.next;
        //     }
        //     p3.next = p2;
        // }
        ListNode t = sz1>sz2?l1:l2;
        while(t!=null){
            if(t.val>9){
                if(t.next==null){
                    t.next = new ListNode(1);
                }else{
                    t.next.val+=1;
                }
                t.val = t.val % 10;
            }
            t = t.next;
        }
        return ret;
    }
}
